export default {
    //设置顶部导航的标题
    setHeaderTitle(state, routerName) {
        switch (routerName) {
            case 'day':
                state.headerTitle = '当天信息';
                break;
            case 'month':
                state.headerTitle = '近期假期';
                break;
            case 'year':
                state.headerTitle = '当年假期';
                break;
            default:
                state.headerTitle = '当天信息';
                break;
        }
    },

    //设置搜索输入框的placeholder
    setPlaceholder(state, routerName) {
        const date = new Date();
        let year = date.getFullYear(),
            month = date.getMonth() + 1,
            day = date.getDate();
        month = month < 10 ? '0' + month : month;
        day = day < 10 ? '0' + day : day;
        switch (routerName) {
            case 'day':
                state.placeholder = `格式：${year}${month}${day}（${year}年${month}月${day}日）`;
                break;
            case 'month':
                state.placeholder = `格式：${year}${month}（${year}年${month}月）`;
                break;
            case 'year':
                state.placeholder = `格式：${year}（${year}年）`;
                break;
            default:
                state.placeholder = `格式：${year}${month}${day}（${year}年${month}月${day}日）`;
                break;
        }
    },

    //设置搜索输入框的最大输入长度
    setMaxlength(state, routerName) {
        switch (routerName) {
            case 'day':
                state.maxlength = 8;
                break;
            case 'month':
                state.maxlength = 6;
                break;
            case 'year':
                state.maxlength = 4;
                break;
            default:
                state.maxlength = 8;
                break;
        }
    },

    //接口返回的错误码（请求成功：0）
    setErrorCode(state, errorCode) {
        state.errorCode = errorCode;
    },

    //路由当前的状态：day、month、year
    setField(state, field) {
        state.field = field;
    },

    //根据路由的状态field设置对应的数据
    setData(state, playload) {
        const { field, data } = playload;
        switch (field) {
            case 'day':
                state.dayData = data;               
                break;
            case 'month':
                state.monthData = data;
                break;
            case 'year':
                state.yearData = data;
                break;
            default:
                state.dayData = data;
                break;
        }
    }

}